<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>

<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="com.ignou.mca.beans.*"%>
<%@ page import="com.ignou.mca.model.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%>
<%@page import="com.ignou.mca.datasource.DataBaseUtilities"%>
<%@page import="com.ignou.mca.datasource.Encryption"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Voting Results</title>
<link rel="stylesheet" href="theme/Master.css" type="text/css">
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0"
	bgcolor="#FFFFFF">
	<tr>
		<td height="21" bgcolor="#495e83"></td>
		<td height="21" bgcolor="#495e83"></td>
	</tr>
	<tr>
		<td height="119" align="left" valign="middle" bgcolor="#FFFFFF">
		<img alt="" src="././images/company_logo.JPG" width="304" height="53">
		</td>
		<td align="right" width="287"><img alt=""
			src="images/header_graphic.jpg" width="287" height="119"></td>
	</tr>
	<tr>
		<td height="45" valign="middle" bgcolor="#495e83">&nbsp; &nbsp;
		&nbsp; <a href="AdminMenu.jsp" class="links" target="">Main Menu</a> &nbsp;
		&nbsp; &nbsp; &nbsp; <a href="Logout.jsp" class="links" target="">Logout</a></td>

		<td bgcolor="#495e83"></td>
	</tr>
	<tr>
		<td height="1"><img alt="" src="images/spacer.gif" width="1"
			height="1"></td>
		<td height="1"><img alt="" src="images/spacer.gif" width="1"
			height="1"></td>
	</tr>
	<tr background="images/links_bot_fill.gif">
		<td height="30">&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="5"
	bgcolor="#FFFFFF">
	<tr>
		<td bgcolor="#FFFFFF" width="20"><img alt=""
			src="images/spacer.gif" width="20" height="10"></td>
		<td bgcolor="#FFFFFF" align="left" valign="top" class="text"
			height="309" width="99%"><br>
		<!-- #BeginEditable "content" -->
		<p class="title" align="center">Voting Results</p>
		<table width="100%" height="100%" border="2">
			<tr>
				<td><font color="red">Post/Parties</font></td>
				<%
					DataBaseUtilities dbu = new DataBaseUtilities();
					Connection conn = dbu.getConnection();

					ResultSet rs1 = dbu.showVoting();
					Collection<PartiesVO> partiesCollection = new ArrayList<PartiesVO>();
					while (rs1.next()) {
						PartiesVO paritesVo = new PartiesVO();
						paritesVo.setPartyID(rs1.getInt(1));
						paritesVo.setPartyName(rs1.getString(2));
						paritesVo.setCandidateName(rs1.getString(3));
						paritesVo.setPost(rs1.getString(4));
						partiesCollection.add(paritesVo);
						out.println("<td><b>" + paritesVo.getPartyName() + "</b></td>");
					}
					ApplicationModel.getIntance().parites = partiesCollection;
				%>
			</tr>
			<%
				Collection<PositionsVO> posts = new ArrayList<PositionsVO>();
				Statement st = conn.createStatement();
				rs1 = st.executeQuery("select * from positions");
				while (rs1.next()) {
					PositionsVO post = new PositionsVO();
					post.setId(Integer.parseInt(rs1.getString("id")));
					post.setName(rs1.getString("name"));
					post.setDescription(rs1.getString("description"));
					posts.add(post);
				}
				ApplicationModel.getIntance().positions = posts;
			%>
			<%
				Iterator<PositionsVO> it = posts.iterator();
				while (it.hasNext()) {
					PositionsVO postion = (PositionsVO) it.next();
					out.println("<tr><td>");
					out.println("<b>" + postion.getName() + "</b></td>");
					Iterator<PartiesVO> partiesIterator = partiesCollection
							.iterator();

					while (partiesIterator.hasNext()) {

						PartiesVO partie = partiesIterator.next();

						st = conn.createStatement();
						rs1 = st
								.executeQuery("select count(*) from votedetails where partyID="
										+ partie.getPartyID()
										+ " AND positionId="
										+ postion.getId());

						out.println("<td>");
						if (rs1.next()) {
							out.println(rs1.getString(1));

						} else {
							out.println("0");
						}
					}
					out.println("</td>");
					out.println("</tr>");
				}
			%>
		</table>
		<br><br>
</tr>
  <tr>
    <td bgcolor="#495e83" width="20">&nbsp;</td>
    <td height="35" align="center" valign="middle" bgcolor="#495e83" class="footer">Copyright
      &copy; 2011 All Rights Reserved. Designed by Pradeepthi S</td>
    <td bgcolor="#495e83" width="20">&nbsp;</td>

  </tr>

</table>

</body>
</html>